package cn.itcast.itcaststore.web.servlet.client;

import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * 删除订单
 *
 */
@WebServlet("/delOrderById")
public class DelOrderByIdServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 订单id
        String id = request.getParameter("id");
        // 已支付的订单带有type值为client的参数
        String type = request.getParameter("type");
        OrderService service = new OrderServiceImpl();
        if (type != null && type.trim().length() > 0) {
            service.delOrderById(id);
            if ("admin".equals(type)) {
                request.getRequestDispatcher("/findOrders").forward(request, response);
                return;
            }
        } else {
            // 调用service层方法删除相应订单
            service.delOrderByIdWithClient(id);
        }
        request.getRequestDispatcher("findOrderByUser").forward(request, response);
        return;
    }
    }

